<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="EmployeeKPILinking.aspx.cs" Inherits="AppraisalManagement.EmployeeKPILinking" %>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <table border="2" cellpadding="1" cellspacing="1">

    <tr>
        <td>
        Select Employee
        </td>    
        <td>
            <asp:DropDownList ID="EmpDropDownList" runat="server" AutoPostBack="True" 
                DataSourceID="EmployeeDataSource" DataTextField="empname" 
                DataValueField="emp_pk">
            </asp:DropDownList>
            <asp:SqlDataSource ID="EmployeeDataSource" runat="server" 
                ConnectionString="<%$ ConnectionStrings:balancescorecardConnectionString %>" 
                
                SelectCommand="SELECT emp_pk, emp_comp_id + '_' + emp_name AS empname FROM employee_details WHERE   (emp_active = 1)">
            </asp:SqlDataSource>
        </td>
    </tr>
    <tr>
    
        <td colspan = "2">
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                DataSourceID="EmpRefDataSource">
                <Columns>
                    <asp:BoundField DataField="grade_name" HeaderText="grade_name" 
                        SortExpression="grade_name" />
                    <asp:BoundField DataField="job_title" HeaderText="job_title" 
                        SortExpression="job_title" />
                    <asp:BoundField DataField="group_name" HeaderText="group_name" 
                        SortExpression="group_name" />
                    <asp:BoundField DataField="dept_name" HeaderText="dept_name" 
                        SortExpression="dept_name" />
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="EmpRefDataSource" runat="server" 
                ConnectionString="<%$ ConnectionStrings:balancescorecardConnectionString %>" 
                SelectCommand="SELECT grade.grade_name, job.job_title, [group].group_name, department.dept_name FROM employee_details INNER JOIN grade ON employee_details.emp_grade_id = grade.grade_pk INNER JOIN [group] ON employee_details.emp_group_id = [group].group_pk INNER JOIN job ON employee_details.emp_job_id = job.job_pk INNER JOIN department ON employee_details.emp_dept_id = department.dept_pk WHERE (employee_details.emp_pk = @emp_pk)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="EmpDropDownList" Name="emp_pk" 
                        PropertyName="SelectedValue" />
                </SelectParameters>
            </asp:SqlDataSource>
        </td>
    
    </tr>
    
    <tr>
        <td>
        Assign Manager
        </td>    
        <td>
            <asp:DropDownList ID="managerDropDown" runat="server" 
                DataSourceID="ManagerDataSource" DataTextField="empname" 
                DataValueField="emp_pk">
            </asp:DropDownList>
            <asp:SqlDataSource ID="ManagerDataSource" runat="server" 
                ConnectionString="<%$ ConnectionStrings:balancescorecardConnectionString %>" 
                SelectCommand="SELECT emp_pk, emp_comp_id + '_' + emp_name AS empname FROM employee_details WHERE (is_manager = 1) AND (emp_active = 1)">
            </asp:SqlDataSource>
        </td>
    </tr>

    <tr>
        <td colspan="2">
        
            <table border="1">
                <tr>
                    <td>Select KPI Group</td>
                    <td>Select KPI</td>
                    <td>Maximum Score</td>
                    <td>Total Score</td>
                </tr>
               
                <tr>
                    <td> 
                        <asp:DropDownList ID="kPIGroupDropDown" runat="server" AutoPostBack="True" 
                            DataSourceID="KPIGroupDataSource" DataTextField="kpi_group_name" 
                            DataValueField="kpi_group_id_pk">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="KPIGroupDataSource" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:balancescorecardConnectionString %>" 
                            SelectCommand="SELECT kpi_group_name, kpi_group_id_pk FROM kpi_group WHERE (kpi_group_active = 1)">
                        </asp:SqlDataSource>
                    </td>
                    <td>
                        <asp:DropDownList ID="KPIDropDown" runat="server" DataSourceID="KPIDataSource" 
                            DataTextField="kpi_name" DataValueField="kpi_id_pk">
                        </asp:DropDownList> 
                        <asp:SqlDataSource ID="KPIDataSource" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:balancescorecardConnectionString %>" 
                            SelectCommand="SELECT kpi_id_pk, kpi_name, kpi_group_id_pk FROM kpi WHERE (kpi_group_id_pk = @groupKPI_pk) AND (kpi_active = 1)">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="kPIGroupDropDown" Name="groupKPI_pk" 
                                    PropertyName="SelectedValue" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                            ControlToValidate="KPIDropDown" ErrorMessage="KPI is required"></asp:RequiredFieldValidator>
                    </td>
                    <td> 
                        <asp:TextBox ID="txtMaxScore" runat="server"></asp:TextBox> 
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                            ControlToValidate="txtMaxScore" ErrorMessage="Score is required" 
                            SetFocusOnError="True"></asp:RequiredFieldValidator>
                        <asp:CustomValidator ID="CustomValidator1" runat="server" 
                            ClientValidationFunction="checkScore" ControlToValidate="txtMaxScore" 
                            ErrorMessage="Number is required" SetFocusOnError="True" 
                            ValidateEmptyText="True" 
                            onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
                    </td>
                    <td> </td>
                </tr>
            </table>
        
        </td>
    </tr>
    <tr>
        <td colspan="2" align="right">
            <asp:Button ID="Save" runat="server" Text="Save KPI" onclick="Save_Click" />                  
        </td>
    </tr>

    <tr>
        <td colspan="2">
            <asp:SqlDataSource ID="KPIEmpLinkDataSource" runat="server" 
                ConnectionString="<%$ ConnectionStrings:balancescorecardConnectionString %>" 
                
                
                SelectCommand="SELECT employee_details.emp_comp_id + '_' + employee_details.emp_name AS empname, kpi.kpi_name, kpi_group.kpi_group_name, Employee_KPI_Linking.max_score, employee_details_1.emp_comp_id + '_' + employee_details_1.emp_name AS manager FROM Employee_KPI_Linking INNER JOIN kpi ON Employee_KPI_Linking.fk_kpi_pk = kpi.kpi_id_pk INNER JOIN kpi_group ON kpi.kpi_group_id_pk = kpi_group.kpi_group_id_pk INNER JOIN employee_details ON Employee_KPI_Linking.fk_emp_pk = employee_details.emp_pk INNER JOIN employee_details AS employee_details_1 ON Employee_KPI_Linking.fk_manager_pk = employee_details_1.emp_pk WHERE (employee_details.emp_pk = @emppk)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="EmpDropDownList" Name="emppk" 
                        PropertyName="SelectedValue" />
                </SelectParameters>
            </asp:SqlDataSource>
            <asp:GridView ID="KPIEmpLinkGridView" runat="server" AllowPaging="True" 
                AllowSorting="True" AutoGenerateColumns="False" 
                DataSourceID="KPIEmpLinkDataSource">
                <Columns>
                    <asp:CommandField ShowSelectButton="True" />
                    <asp:BoundField DataField="empname" HeaderText="empname" ReadOnly="True" 
                        SortExpression="empname" />
                    <asp:BoundField DataField="kpi_name" HeaderText="kpi_name" 
                        SortExpression="kpi_name" />
                    <asp:BoundField DataField="kpi_group_name" HeaderText="kpi_group_name" 
                        SortExpression="kpi_group_name" />
                    <asp:BoundField DataField="max_score" HeaderText="max_score" 
                        SortExpression="max_score" />
                    <asp:BoundField DataField="manager" HeaderText="manager" ReadOnly="True" 
                        SortExpression="manager" />
                </Columns>
            </asp:GridView>
        </td>        
    </tr>
</table>

<script language="javascript" type="text/javascript">

    function checkScore (source, arguments) {

        arguments.IsValid = !isNaN(arguments.Value);
        
    }

</script>
</asp:Content>
